<?php use Inationsoft\NS\String; ?>
<ul class="nav nav-tabs nav-stacked">
	<li class="nav-header">Menu Utama</li>
	<?php
		$seleted = false;
		$already_selected = false;
	?>
	<?php foreach($menus as $menu): ?>
	<?php if(count($menu['menu_links']) > 0): ?>
	<?php
		if(!$already_selected) {
			$urls = array();
	
			foreach($menu['menu_links'] as $link) {
				$urls[] = str_replace('/', '\/', NS_BASE_URL . '/' . $link['url']);
			}
	
			$already_selected = $seleted = String::startsWith(NS_CURRENT_URL, $urls);
		}
	?>
	<li class="dropdown<?php if($seleted) echo ' active'; ?>">
	<?php else: ?>
	<li>
	<?php endif; ?>
		<?php if(count($menu['menu_links']) > 0): ?>
		<a href="<?php echo ($menu['url'] == '#' ? $menu['url'] : NS_BASE_URL . '/' . $menu['url']); ?>"><?php echo $menu['display_content']; ?></a>
		<ul<?php if($seleted) echo ' style="display: block;"'; ?>>
			<?php foreach($menu['menu_links'] as $link): ?>
			<li>
				<a href="<?php echo NS_BASE_URL, '/', $link['url']; ?>"><?php echo $link['menu_link_name']; ?></a>
			</li>
			<?php endforeach; ?>
		</ul>
		<?php else: ?>
			<a href="<?php echo ($menu['url'] == '#' ? $menu['url'] : NS_BASE_URL . '/' . $menu['url']); ?>">
				<?php echo $menu['display_content']; ?>
			</a>
		<?php endif; ?>
	</li>
	<?php if($seleted) $seleted = false; ?>
	<?php endforeach; ?>
</ul>